using System.IO;

namespace Google.Protobuf
{
    public static class CodedInputStreamFactory
    {
        private static CodedInputStream codedInputStream = null;
        public static CodedInputStream Get(byte[] data)
        {
            if (codedInputStream == null) 
            { 
                codedInputStream = new CodedInputStream(data);
            }
            else
            {
                codedInputStream.Init(data);
            }

            return codedInputStream;
        }

        public static CodedInputStream Get(byte[] buffer, int offset, int length)
        {
            if (codedInputStream == null)
            {
                codedInputStream = new CodedInputStream(buffer, offset, length);
            }
            else
            {
                codedInputStream.Init(buffer, offset, length);
            }

            return codedInputStream;
        }

        public static CodedInputStream Get(Stream input)
        {
            if (codedInputStream == null)
            {
                codedInputStream = new CodedInputStream(input);
            }
            else
            {
                codedInputStream.Init(input);
            }

            return codedInputStream;
        }
    }
}

